﻿using System.Collections.Generic;
using System.Linq;
using Faz.SideWinderSC.Logic;

namespace Faz.SideWinderSC.Client.ViewModel
{
    /// <summary>
    /// Defines the view-model that manages the configuration per controller model.
    /// </summary>
    public class ModelViewModel : AbstractViewModel
    {
        private readonly Model model;

        /// <summary>
        /// The available profiles.
        /// </summary>
        private readonly ICollection<ProfileViewModel> profiles;

        /// <summary>
        /// Initializes a new instance of the <see cref="ModelViewModel"/> class.
        /// </summary>
        public ModelViewModel(Model model)
        {
            this.model = model;
            this.profiles = new ViewModelCollection<ProfileViewModel>(this.LoadProfiles);
        }

        /// <summary>
        /// Gets the name of the model.
        /// </summary>
        public string Name
        {
            get { return this.model.Name; }
        }

        /// <summary>
        /// Gets the available profiles.
        /// </summary>
        public ICollection<ProfileViewModel> Profiles
        {
            get { return this.profiles; }
        }

        /// <summary>
        /// Loads the profiles associated with the model.
        /// </summary>
        /// <returns>The associated profiles.</returns>
        private IEnumerable<ProfileViewModel> LoadProfiles()
        {
            return this.model.Profiles.Select(p => new ProfileViewModel(p));
        }
    }
}
